﻿

namespace FileStrider
{
    using System.IO;
    using System.Windows.Controls;

    /// <summary>
    /// Interaction logic for ListItemFile.xaml
    /// </summary>
    public partial class ListItemFile : UserControl
    {
        public FileInfo File;
        
        public ListItemFile(string fullFileName)
        {
            InitializeComponent();
            
            File = new FileInfo(fullFileName);

            LabelFileName.Content = File.FullName;
            LabelSIze.Content     = (File.Length/1024/1024).ToString("N0") + " Mb";

            // Get file attributes for coloring
            if ((File.Attributes & FileAttributes.Hidden) != 0) { LabelFileName.Foreground     = Helper.HiddenFileColor; }
            if ((File.Attributes & FileAttributes.Encrypted) != 0) { LabelFileName.Foreground  = Helper.EncryptedFileColor; }
            if ((File.Attributes & FileAttributes.Compressed) != 0) { LabelFileName.Foreground = Helper.CompressedFileColor; }

            try
            {
                ImageIcon.Source = Helper.GetDriveIcon(File.FullName);
            }
            catch (Helper.IconReadException)
            {
                // Sometimes unable to retrive folder icon, just skip it
            }
        }
    }
}
